package com.hcl.orm.core.dialect;

import com.hcl.orm.core.executor.page.PageParam;

import java.util.List;
import java.util.function.Function;

/**
 * @author hucl
 * @projectName hcl-orm
 * @description: TODO
 * @date 2021/8/1016:17
 */
public class SqlDefinition {
    /**
     * 本地化的Sql元数据
     */
    private List<SqlMetadata> nativeSqlMetadatas;
    /**
     * 选中的Sql元数据
     */
    private SqlMetadata selectedSqlMetadata;
    /**
     * 标准SQL元数据
     */
    private SqlMetadata stdSqlMetadata;
    /**
     * 方法签名
     */
    private Signature signature;
    /**
     * 统计SQL
     */
    private String pageQueryCountSql;
    /**
     * 转换后的数据库方言函数
     */
    private String dialectSql;
    /**
     * 分页参数的排列规则
     *
     * @return
     */
    private Function<PageParam, Object[]> pageParamFunction;


    public SqlDefinition(SqlMetadata stdSqlMetadata, List<SqlMetadata> nativeSqlMetadatas, Signature signature) {
        this.stdSqlMetadata = stdSqlMetadata;
        this.nativeSqlMetadatas = nativeSqlMetadatas;
        this.signature = signature;
    }


    public Signature getSignature() {
        return signature;
    }

    public List<SqlMetadata> getNativeSqlMetadatas() {
        return nativeSqlMetadatas;
    }

    public SqlMetadata getSelectedSqlMetadata() {
        return selectedSqlMetadata;
    }

    public void setSelectedSqlMetadata(SqlMetadata selectedSqlMetadata) {
        this.selectedSqlMetadata = selectedSqlMetadata;
    }

    public SqlMetadata getStdSqlMetadata() {
        return stdSqlMetadata;
    }

    public String getRawSql() {
        return this.selectedSqlMetadata.getRawSql();
    }


    public String getDialectSql() {
        return dialectSql;
    }

    public void setDialectSql(String dialectSql) {
        this.dialectSql = dialectSql;
    }


    public String getPageQueryCountSql() {
        return this.pageQueryCountSql;
    }

    public void setPageQueryCountSql(String countSql) {
        this.pageQueryCountSql = countSql;
    }

    public Function<PageParam, Object[]> getPageParamFunction() {
        return pageParamFunction;
    }

    public void setPageParamFunction(Function<PageParam, Object[]> pageParamFunction) {
        this.pageParamFunction = pageParamFunction;
    }

    @Override
    public String toString() {
        return "SqlDefinition{" +
                "nativeSqlMetadata=" + nativeSqlMetadatas +
                ", stdSqlMetadata=" + selectedSqlMetadata +
                ", signature=" + signature +
                ", pageQueryCountSql='" + pageQueryCountSql + '\'' +
                ", dialectSql='" + dialectSql + '\'' +
                ", pageParamFunction=" + pageParamFunction +
                '}';
    }
}
